Listing 1 shows AddTweenAtom , a routine that adds an atom of type kTweenEntry plus its standard child atoms (other than the kTweenDataAtom ) to a container. Only the tweenAtomID and tweenerType parameters are required; you may pass 0 for the other parameters to avoid using them.
The minOutput and maxOutput atom parameters are necessary only if the tweener is being used as an interpolator. Passing a tweenAtomID value of 0 means that the routine can assign any unique ID.
If you use AddTweenAtom to add a nonsequenced tween entry to a container, the kTweenEntry atom it creates is the atom you pass to QTNewTween and the sequenceAtom you pass in may be kParentAtomIsContainer . In this case the tweenAtomID value should be 1.
If you use AddTweenAtom to add a sequenced tween entry to a container, the newSequenceAtom returned by AddSequenceTweenAtom is its sequenceAtom parameter and will also be the atom you pass to QTNewTween . Note that in most cases a sequenced tween contains only one tween entry but may contain multiple data atoms.
All tween atoms within same sequenceAtom must have same tween type. It is unlikely that you would want to change the duration or offset values within the same sequenceAtom .
Listing 1 Utility routine AddTweenAtom
OSErr AddTweenAtom( QTAtomContainer container, QTAtom sequenceAtom,
QTAtomID tweenAtomID, OSType tweenerType, TimeValue offset,
TimeValue duration, Fixed minOutput, Fixed maxOutput, StringPtr name,
QTAtom *newTweenAtom )
{
OSErr err = noErr;
QTAtom tweenAtom = 0;
if ( ! container ) { err = paramErr; goto bail; }
err = QTInsertChild( container, sequenceAtom, kTweenEntry,
tweenAtomID, 0, 0, nil, &tweenAtom );
if ( err ) goto bail;
err = QTInsertChild( container, tweenAtom, kTweenType, 1, 1,
sizeof(tweenerType), &tweenerType, nil );
if ( err ) goto bail;
if ( offset ) {
err = QTInsertChild( container, tweenAtom, kTweenStartOffset, 1,
1, sizeof(offset), &offset, nil );
if ( err ) goto bail;
}
if ( duration ) {
err = QTInsertChild( container, tweenAtom, kTweenDuration, 1, 1,
sizeof(duration), &duration, nil );
if ( err ) goto bail;
}
// default minOutput is zero, so this is OK
if ( minOutput ) {
err = QTInsertChild( container, tweenAtom, kTweenOutputMin, 1, 1,
sizeof(minOutput), &minOutput, nil );
if ( err ) goto bail;
}
if ( maxOutput ) {
err = QTInsertChild( container, tweenAtom, kTweenOutputMax, 1, 1,
sizeof(maxOutput), &maxOutput, nil );
if ( err ) goto bail;
}
if ( name ) {
err = QTInsertChild( container, tweenAtom, kNameAtom, 1, 1,
name[0] + 1, name, nil );
if ( err ) goto bail;
}
bail:
if ( newTweenAtom )
*newTweenAtom = tweenAtom;
return err;
}
| Previous | Chapter Contents | Chapter Top | Next |